package com.liusand.user.client;

import com.alibaba.fastjson.JSON;
import com.liusand.entity.dto.IdListDto;
import com.liusand.entity.pojo.User;
import com.liusand.entity.vo.Result;
import com.liusand.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author :liusha
 * packageName :com.liusand.user.client
 * fileName :UserClient
 * creationTime :2022/12/24 21:24
 */
@Slf4j
@RestController
@RequestMapping("/user/client")
public class UserClient {

    @Autowired
    private UserService userService;

    @PostMapping("/getUserInfo")
    public Result getUserInfo(@RequestBody IdListDto idListDto){
        if (idListDto == null || CollectionUtils.isEmpty(idListDto.getIds())){
            return Result.error("参数出错");
        }
        List<String> userIds = idListDto.getIds();
        List<User> userList = userService.getUserInfo(userIds);
        return Result.success(JSON.toJSONString(userList));
    }
}
